package Integrity;

import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.util.zip.CRC32;
import java.util.zip.CheckedInputStream;

public class IntegrityUtilityClass {
	
	public static long calculateCRCOfTheFile(String fileName) 
	{		
		FileInputStream file;
		try {
			file = new FileInputStream(fileName);

			CheckedInputStream check = 
				new CheckedInputStream(file, new CRC32());
			BufferedInputStream in = 
				new BufferedInputStream(check);
			while (in.read() != -1) {
				// Read file in completely
			}
			System.out.println("Checksum of "+fileName+ " is " + 
					check.getChecksum().getValue());
			in.close();
			
			return check.getChecksum().getValue();
		
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return 0;	 
	}
}
